Yacon.widget.TCarousel = function(conText){
	
	Yacon.apply(this,conText);
	
};

Yacon.widget.TCarousel.prototype = {
	
	getScrollHtml : function(activeImg){
		
		var html = "";
		
		html += "<div class='scroll-image'>"			
		html += "<div class='modal fade' id='"+this.elementID+"_pic_windows' tabindex='-1' role='dialog'>";	
		html += "<div class='modal-dialog' role='document' ";
		
		if(!Yacon.isEmpty(this.parent.view.picBigWidth)){
			html += " style='width:"+Yacon.getWidthNumber(this.parent.view.picBigWidth)+"px"+"' ";
		}
		
		html += ">";
		html += "<div class='modal-content'>";
		html += "<div class='modal-body' style='padding:0px;'>";	
		
		html += "<div id='"+this.elementID+"' class='carousel slide' data-ride='carousel' data-wrap='"+Yacon.isTrue(this.isWrap)+"'>";
		
		/* 列表图片 */
		html += "<div class='carousel-inner' role='listbox'>";
		
		for(var i=0;i<this.pictures.length;i++){
			
			var picture = this.pictures[i];
			
			html += "<div class='item' img-idx='"+i+"'>";
			
			html += "<img src='"+picture.view.src+"' alt='"+picture.view.alt+"' ";
			
			if(!Yacon.isEmpty(this.parent.view.picBigWidth)){
				html += " style='width:"+Yacon.getWidthNumber(this.parent.view.picBigWidth)+"px"+"' "
			}
			
			else if(!Yacon.isEmpty(this.parent.view.picBigHeight)){
				html += " style='height:"+Yacon.getHeightNumber(this.parent.view.picBigHeight)+"px"+"' "
			}
					
			html += " />";
			
			html += "</div>";
			
		}
		
		html += "</div>";
		
		/* 控制部分 */		
		html += "<a class='left carousel-control' href='#"+this.elementID+"' role='button' data-slide='prev'>";
		html += "<span class='glyphicon glyphicon-chevron-left' aria-hidden='true'></span>";
		html += "<span class='sr-only'>Previous</span>";
		html += "</a>";
		
		html += "<a class='right carousel-control' href='#"+this.elementID+"' role='button' data-slide='next'>";
		html += "<span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>";
		html += "<span class='sr-only'>Next</span>";
		html += "</a>";
		
		html += "</div>";
		
		html += "</div>";
		html += "</div>";
		html += "</div>";
		html += "</div>";	
		html += "</div>";
		
		return html;
		
	},
	
	getBigHtml:function(activeImg){
		
	    var html = "";
	
	    html += "<div class='big-image'>"			
		html += "<div class='modal fade' id='"+this.elementID+"_pic_windows' tabindex='-1' role='dialog'>";	
		html += "<div class='modal-dialog' role='document' ";
		
		if(!Yacon.isEmpty(this.parent.view.picBigWidth)){
			html += " style='width:"+Yacon.getWidthNumber(this.parent.view.picBigWidth)+"px"+"' ";
		}
			
		html += ">";
		
		html += "<div class='modal-content'>";
		html += "<div class='modal-body' style='padding:0px;'>";		
		html += "<img src='"+activeImg.prop("src")+"' alt='"+activeImg.prop("alt")+"' />";		
		html += "</div>";
		html += "</div>";
		html += "</div>";
		html += "</div>";	
		html += "</div>";
		
		return html;
		
	},
	
	show: function(activeImg){
		
		var self = this;
		
		if(Yacon.isTrue(self.parent.view.isScroll)){
			
			$("body").append(this.getScrollHtml(activeImg));
			
			//当前图片
			var idx = activeImg.attr("pic-idx");
			$("#"+self.elementID+"_pic_windows").find("div.item[img-idx='"+idx+"']").addClass("active");
			
			var showImg = $("#"+self.elementID+"_pic_windows").find(".item.active").find("img");
			
			var myimage = activeImg.get(0);
			
			var im = new Image();
		　　   im.src = myimage.src;
		　　   var actureWidth = im.width;
		　　    var actureHeight = im.height;
		　　    
		　　    if(!Yacon.isEmpty(self.parent.view.picBigWidth)){
				showImg.css("width",Yacon.getWidthNumber(self.parent.view.picBigWidth)+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",Yacon.getWidthNumber(self.parent.view.picBigWidth)+"px");
			}
			
			else if(!Yacon.isEmpty(self.parent.view.picBigHeight)){
				
				var activeHeight = Yacon.getHeightNumber(self.parent.view.picBigHeight);
				
				var activeWidth = activeHeight * actureWidth / actureHeight;
				
				showImg.css("height",activeHeight+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",activeWidth+"px");
			}
			
			else{
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",actureWidth+"px");
				showImg.css("width",actureWidth+"px");
				showImg.css("height",actureHeight+"px");
			}
			
			
		}else{
			
			$("body").append(this.getBigHtml(activeImg));
			
			var showImg = $("#"+self.elementID+"_pic_windows").find("img");
			
			var myimage = activeImg.get(0);
			
			var im = new Image();
		　　   im.src = myimage.src;
		　　   var actureWidth = im.width;
		　　    var actureHeight = im.height;
	
			showImg.prop("src",activeImg.prop("src"));
			showImg.prop("alt",activeImg.prop("alt"));
			
			if(!Yacon.isEmpty(self.parent.view.picBigWidth)){
				showImg.css("width",Yacon.getWidthNumber(self.parent.view.picBigWidth)+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",showImg.css("width"));
			}
			
			else if(!Yacon.isEmpty(self.parent.view.picBigHeight)){
				
				var activeHeight = Yacon.getHeightNumber(self.parent.view.picBigHeight);
				
				var activeWidth = activeHeight * actureWidth / actureHeight;
				
				showImg.css("height",activeHeight+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",activeWidth+"px");
			}
			
			else{
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",actureWidth+"px");
			}
			
		}
		
		
		$("#"+self.elementID+"_pic_windows").modal('show');
		
		$("#"+self.elementID+"_pic_windows").on('shown.bs.modal',function (e) {
			$('#'+self.elementID+"_pic_windows").on('hidden.bs.modal', function (e) {
				
				$('#'+self.elementID+"_pic_windows").parent().remove();
				
				var parentSize = $(".modal .modal-dialog").length;
				
				if(parentSize > 0){
					$("body").addClass("modal-open");
				}
				
			});
		});
		
		$(function(){
			if(!Yacon.isTrue(self.parent.view.isWrap)){
				$(".carousel").carousel({
					pause:true,
		            interval: false,
		            wrap:false
				});
			}
		});
		
		$("#"+self.elementID+"_srollBox_pics").on('slid.bs.carousel', function () {
			
			var showImg = $("#"+self.elementID+"_srollBox_pics").find(".item.active").find("img");
			
			var myimage = showImg.get(0);
			
			var im = new Image();
		　　   im.src = myimage.src;
		　　   var actureWidth = im.width;
		　　    var actureHeight = im.height;
		　　    
		　　    if(!Yacon.isEmpty(self.parent.view.picBigWidth)){
				showImg.css("width",Yacon.getWidthNumber(self.parent.view.picBigWidth)+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",Yacon.getWidthNumber(self.parent.view.picBigWidth)+"px");
			}
			
			else if(!Yacon.isEmpty(self.parent.view.picBigHeight)){
				
				var activeHeight = Yacon.getHeightNumber(self.parent.view.picBigHeight);
				
				var activeWidth = activeHeight * actureWidth / actureHeight;
				
				showImg.css("height",activeHeight+"px");
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",activeWidth+"px");
			}
			
			else{
				$("#"+self.elementID+"_pic_windows .modal-dialog").css("width",actureWidth+"px");
				showImg.css("width",actureWidth+"px");
				showImg.css("height",actureHeight+"px");
			}
			
		});
		
	}

};